<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link th:href="@{/layer/css/layui.css}" rel="stylesheet">
    <link th:href="@{/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <script type="text/javascript" th:src="@{/js/jquery-3.2.1.min.js}" ></script>
    <script th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{/layer/layui.js}"></script>
    <script type="text/javascript" th:src="@{/js/common.js}" ></script>
    <style>
        .layui-form-label {
            width: 100px;
        }

    </style>
</head>
<body class="childrenBody">
<form class="layui-form" id="userFrm" >
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">卡号</label>
            <div class="layui-input-inline">
                <input type="text" name="membernumber" id="membernumber"
                       autocomplete="off" onclick="checkit()" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="clientname" id="clientname" placeholder="用户姓名" autocomplete="off" class="layui-input">
            <input class="hidden" id="clientid" name="clientid">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block" >
                <input type="text" name="phoneNumber" id="phoneNumber" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block" >
                <a href="javascript:void(0)" onclick="seachclient()" class="search_btn layui-btn" id="searchBtn">
                    <i class="layui-icon layui-icon-search"></i>
                </a>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">证件号码</label>
            <div class="layui-input-inline">
                <input type="text" name="identity" id="identity" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">证件类型</label>
            <div class="layui-input-inline">
                <input type="text" name="idType" id="idType" placeholder="" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

    </div>
    <div class="layui-inline">
        <label class="layui-form-label">会员生日</label>
        <div class="layui-input-inline">
            <input type="date" name="birthday" id="birthday" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-inline">
            <input type="text" name="unit" id="unit" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" id="adress" name="adress" placeholder="地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <button class="layui-btn" lay-submit="" lay-filter="addUser">提交</button>
        <button class="layui-btn layui-btn-warm" type="reset">重置</button>
    </div>
</form>
<script>
    var form;
    var layer;
    layui.use(['layer','form','jquery'],function () {
        form = layui.form;
        layer = parent.layer === undefined ? layui.layer : parent.layer;
        var $ = layui.jquery;

        form.on('submit(addUser)',function () {
            var data =$('#userFrm').serialize();
            $.post('/member/addMemberone',data,function (data) {
                console.log(data);
                if (data.code == 0) {
                    //弹出成功的提示
                    layer.msg(data.msg, {icon: 1, time: 2000});
                    //重载表格
                    parent.tableIns.reload();
                    //关闭窗口
                    var index = layer.getFrameIndex(window.name);
                    layer.close(index);
                } else {
                    layer.msg(data.msg, {icon: 2, time: 3000});
                }
            });
            return false;
            });

    });
    function checkit() {
        var num = "";
        for (var i=0;i<8;i++){
            num +=Math.floor(Math.random()*10);
        }
        $("#membernumber").val(num);
    }
    function seachclient () {
        var clientname = $("#clientname").val();
        var phoneNumber = $("#phoneNumber").val();
        $.post("/member/getclientId",{ clientname:clientname,
            phoneNumber:phoneNumber
        },function (data) {
            console.log(data);
            if (data == "没有找到"){
                layer.msg("没有找到", {icon: 2, time: 3000});
            }
            else{
                var n = JSON.parse(data)
                var logs = $("#clientid").val(n.clientid);
                $("#identity").val(n.identity);
            }
        })
    };
    $("#identity").blur(function () {
        var idCard = idCardNo($("#identity").val());
        if (idCard == false){
            layer.msg("身份证有误，请检查！");
        }
        else{
           var getB = getBirth($("#identity").val());
            $("#birthday").val(getB);
        }
    });
    $("#phoneNumber").blur(function () {
        var phone = getPhone($("#phoneNumber").val());
        if (phone == false){
            layer.msg("手机号码有误，请检查！");
        }
    });
</script>
</body>
</html>